'''
Created on 03/09/2013

@author: loski07@gmail.com
'''

class Visitor(object):
    """
    General visitor
    """
    def visit(self, node):
        '''Visit a node'''
        print "Error, the class does not overwrite visit"
        pass

    def default(self, node):
        '''
        Visit node children
        '''
        for child in node.subdirs:
            self.visit(child)
            
class AlphaSorter(Visitor):
    """
    Visitor to sort the tree in alphabetical order
    """
    def visit(self, node):
        """
        Visits Tree nodes
        """
        self.default(node)
        if node.songs:
            node.songs = sorted(node.songs, key = lambda song: song.filename)

class ID3Sorter(Visitor):
    """
    Visitor to sort the tree in the order defined in the id3 tag
    """
    def visit(self, node):
        """
        Visits Tree nodes
        """
        self.default(node)
        if node.songs:
            node.songs = sorted(node.songs, key = lambda song: song.id3)
    